/* 讨论区 */
import request from '@/utils/request.js'

export const postTag = (tagName) => request(`/post/tags?tagName=${ tagName }`, 'POST')

/**
 * 获取平台所有讨论标签
 */
export const getDiscussionTags = () => request('/post/tags/all', 'GET')

/**
 * 发布讨论
 * @param {String}  title
 * @param {String}  content
 * @param {Number}  tagId
 */
export const postDiscussion = (data) => request('/post', 'POST', data)

/**
 * 删除讨论
 * @param {String}  postId
 */
export const deleteDiscussion = (postId) => request(`/post/${ postId }`, 'DELETE')

/**
 * 修改讨论
 * @param {String}  postId
 * @param {String}  title
 * @param {String}  content
 * @param {Number}  tagId
 */
export const putDiscussion = ({ postId, ...data }) => request(`/post/${ postId }`, 'PUT', data)

/**
 * 获取特定标签下的讨论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {String}  strategy 策略 hottest-最热, latest-最新（默认)
 * @param {Number}  tag 标签ID
 */
export const getDiscussions = ({ tagId, ...params }) => request(`/post/tag/${ tagId }`, 'GET', params)

/**
 * 获取所有讨论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {String}  strategy 策略 hottest-最热, latest-最新（默认)
 */
export const getAllDiscussions = (params) => request(`/post/keywords`, 'GET', params)

/**
 * 获取指定用户的讨论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 */
export const getUserDiscussions = ({ userId, ...params }) => request(`/post/u/${ userId }`, 'GET', params)

/**
 * 获取讨论详细
 * @param {String}  postId
 */
export const getDiscussion = (postId) => request(`/post/detail/${ postId }`, 'GET')

/**
 * 获取我收藏/点赞的讨论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Boolean}  isLike true-点赞的（默认),false-收藏的
 */
export const getMylikeDiscussion = (params) => request('/post/myLike', 'GET', params)

/**
 * 获取我历史讨论记录
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 */
export const getHistoryDisc = (params) => request('/post/history', 'GET', params)

/**
 * 点赞 / 取消点赞讨论帖子
 * @param {Boolean}  isLike true-点赞false-取消点赞
 */
export const likeDiscussion = (postId, isLike) => request(`/post/like/${ postId }?isLike=${ isLike }`, 'POST')

/**
 * 收藏 / 取消收藏讨论帖子
 * @param {Boolean}  isCollect true-收藏 false-取消收藏
 */
export const collectDiscussion = (postId, isCollect) => request(`/post/collection/${ postId }?isCollect=${ isCollect }`, 'POST')

/**
 * 分页获取讨论评论内容
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number} replyNum 每条评论的回复数量
 * @param {String} loadBy 策略 hottest-最热（默认), latest-最新
 */
export const getDiscComments = ({ postId, ...params }) => request(`/post/${ postId }/comments`, 'GET', params)

/**
 * 获取单条评论信息
 * @param {String}  commentId
 * @param {Number} replyNum 回复条数
 */
export const getComment = ({ commentId, replyNum }) => request(`/post/comment/${ commentId }`, 'GET', { replyNum })

/**
 * 点赞 / 取消点赞评论内容
 * @param {Boolean}  isLike true-点赞false-取消点赞
 */
export const likeDiscComment = (commentId, isLike) => request(`/post/comment/like/${ commentId }?isLike=${ isLike }`, 'POST')

/**
 * 发布评论
 * @param {String}  postId 讨论帖子ID
 * @param {String}  content
 */
export const postDiscComment = (data) => request('/post/comment', 'POST', data)

/**
 * 删除评论
 * @param {String}  commentId
 */
export const deleteDiscComment = (commentId) => request(`/post/comment/${ commentId }`, 'DELETE')

/**
 * 分页获取讨论的评论的回复内容
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {String} loadBy 策略 hottest-最热（默认), latest-最新
 */
export const getDiscCommentsReply = ({ commentId, ...params }) => request(`/post/comment/${ commentId }/replies`, 'GET', params)

/**
 * 分页获取我的回复内容
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 */
export const getMyReply = ({ userId, ...params }) => request(`/post/reply/u/${ userId }`, 'GET', params)

/**
 * 点赞 / 取消点赞回复内容
 * @param {Boolean}  isLike true-点赞false-取消点赞
 */
export const likeDiscCommentReply = (replyId, isLike) => request(`/post/comment/reply/like/${ replyId }?isLike=${ isLike }`, 'POST')

/**
 * 发布回复
 * @param {Number}  toId 被回复对象的用户Id
 * @param {String}  commentId 评论ID
 * @param {String}  content
 */
export const postDiscCommentReply = (data) => request('/post/comment/reply', 'POST', data)

/**
 * 删除回复
 * @param {String}  replyId
 */
export const deleteDiscCommentReply = (replyId) => request(`/post/comment/reply/${ replyId }`, 'DELETE')

/**
 * 分页获取用户发布的评论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  replyNum 评论数量
 * @param {String} loadBy 策略 hottest-最热（默认), latest-最新
 */
export const getUserComments = ({ userId, ...params }) => request(`/post/comment/u/${ userId }`, 'GET', params)
